﻿Imports GisMapF
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.IO
Public Class frmGis
    Private m_GridData(,) As Double
    Private m_Max As Double   '网格点的最大值
    Private m_Min As Double  '网格点中的最小值

    Property GridData() As Double(,)
        Get
            Return Me.m_GridData
        End Get
        Set(ByVal value As Double(,))
            Me.m_GridData = value
        End Set
    End Property
    ''' <summary>
    ''' 网格点的最大值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Max() As Double
        Get
            Return Me.m_Max
        End Get
        Set(ByVal value As Double)
            Me.m_Max = value
        End Set
    End Property
    ''' <summary>
    ''' 网格点中的最小值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property Min() As Double
        Get
            Return Me.m_Min
        End Get
        Set(ByVal value As Double)
            Me.m_Min = value
        End Set
    End Property

    Public m_manager As LayerManager

    Public Sub New(ByVal strProjPath As String)

        ' 此调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        ' 在 InitializeComponent() 调用之后添加任何初始化。
        m_manager = New LayerManager(AxMap1, strProjPath)

    End Sub
    Private Sub frmMainV2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        ' 关心点 点层的例子，哈哈
        Dim ptool As New PointTool()

        Dim cpLayer As New ESPointLayer("cpoint_1", ptool)
        cpLayer.LdescProperty = "点源"

        m_manager.AddLayer(cpLayer)


        '点源


        Dim cpLayer2 As New ESPointLayer("ppoint_1", New PointTool)


        m_manager.AddLayer(cpLayer2)


        '线源

        Dim layer3 As New ESMLineLayer("pline_1", New CPlineTool)

        m_manager.AddLayer(layer3)

        '多边形源

        Dim layer4 As New ESPolylineLayer("poly_1", New PolyTool)

        m_manager.AddLayer(layer4)


        '体源
        Dim layer5 As New ESPolylineLayer("cube_1", New SquareTool)

        m_manager.AddLayer(layer5)

        '圆形面源
        Dim layer6 As New ESCriclePolyLayer("circle_1", New CircleTool)

        m_manager.AddLayer(layer6)

        '矩形面源

        Dim layer7 As New ESPolylineLayer("rect_1", New RectangleTool)

        m_manager.AddLayer(layer7)

        '敞口源



        Dim layer8 As New ESPolylineLayer("exp_1", New RectangleTool)

        m_manager.AddLayer(layer8)

        '建筑物

        Dim layer9 As New ESPolylineLayer("build_1", New RectangleTool)

        m_manager.AddLayer(layer9)

        '为噪声应用所准备的层
        Dim layer10 As New ESPolygonLayer("polygon_1", New PolyTool)




        m_manager.AddLayer(layer10)

        '具体属性的设置要在addlayer之后访问
        layer10.FilltypeProperty = MapWinGIS.tkFillStipple.fsDiagonalDownRight


        '来个小网格
        Dim grd As New SDSGridLineLayer("grid_1")

        m_manager.AddLayer(grd)



        'grd.LBPointXAProperty = 20000
        'grd.LBPointYAProperty = 30000






        '等值线
        Dim con As New SDSContourLayer("contour_1")
        m_manager.AddLayer(con)




        '坐标轴
        Dim axis As New SDSAxisLayer("axis_1")
        m_manager.AddLayer(axis)

        '地形
        'Dim ter As New ImageLayer("terrain", "c:\test\utm.dem")
        'm_manager.AddLayer(ter)



    End Sub
    Private Sub frmGis_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Public Sub InitalContour(ByVal Grid(,) As Double)
        Try
            Dim cpLayer As SDSContourLayer
            m_manager.GetLayer("contour_1", cpLayer)
            cpLayer.MyContours.GridPoint = Grid
            '设置等值线名称和值的数组
            Dim n As Integer = 5
            Dim Increase As Double = 0
            Dim dblA(-1) As Double

            If m_Max <> -999999999 And m_Max > 0 Then
                m_Min = m_Max / 20
                Increase = (m_Max / 2 - m_Min) / n
                For j As Integer = 0 To 10 '选取整数来分析
                    If CInt(Increase * 10 ^ j) > 0 Then
                        Increase = CInt(Increase * 10 ^ j) / 10 ^ j
                        Exit For
                    End If
                Next

                m_Min = m_Min + Increase
                For j As Integer = 0 To 10 '选取整数来分析
                    If CInt(m_Min * 10 ^ j) > 0 Then
                        m_Min = CInt(m_Min * 10 ^ j) / 10 ^ j
                        Exit For
                    End If
                Next


                For i As Integer = 0 To n - 1
                    Dim dblValue As Double = m_Min + Increase * i
                    ReDim Preserve dblA(dblA.Length)
                    dblA(dblA.Length - 1) = dblValue
                    If dblA.Length >= 5 Then
                        Exit For
                    End If
                Next
            End If


            ReDim cpLayer.MyContours.ContourValueSetting.ContourNames(dblA.Length - 1)
            ReDim cpLayer.MyContours.ContourValueSetting.ContourValue(dblA.Length - 1)
            For i As Integer = 0 To dblA.Length - 1
                cpLayer.MyContours.ContourValueSetting.ContourNames(i) = FormatNumber(dblA(i), 5, TriState.True, TriState.False, TriState.False)
                cpLayer.MyContours.ContourValueSetting.ContourValue(i) = FormatNumber(dblA(i), 5, TriState.True, TriState.False, TriState.False)
            Next
            cpLayer.MyContours.ContourValueSetting.ContourValueType = 1
            cpLayer.MyContours.ReCalContour = True



            '提供集合的初始化，以及默认值
            Dim cList As List(Of ContourLine)
            cList = New List(Of ContourLine)
            Dim conl As ContourLine

            conl = New ContourLine()
            conl.VProperty = 0.001
            conl.ClrProperty = Drawing.Color.Yellow
            cList.Add(conl)

            conl = New ContourLine()
            conl.VProperty = 0.002
            conl.ClrProperty = Drawing.Color.FromArgb(255, 128, 0)
            cList.Add(conl)

            conl = New ContourLine()
            conl.VProperty = 0.003
            conl.ClrProperty = Drawing.Color.FromArgb(255, 128, 128)
            cList.Add(conl)

            conl = New ContourLine()
            conl.VProperty = 0.004
            conl.ClrProperty = Drawing.Color.Red
            cList.Add(conl)

            If m_Min >= m_Max Then
                MsgBox("计算结果均为0，无法作出等值线图，请您检查污染源强数据!")
                Exit Sub
            End If
        Catch ex As Exception
        End Try
        '-----------------------------------

    End Sub
End Class
